<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 模拟斗地主发牌 -->
    <script>
      function creatPoker() {
        let paidui = []
        let color = ['黑桃', '红桃', '梅花', '方块']
        let number = ['3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A', '2']
        for (let i = 0; i < number.length; i++) {
          let forColor = number[i]
          for (let j = 0; j < color.length; j++) {
            let forNum = color[j]
            paidui.push(forNum + forColor)
          }
        }
        paidui.push('小王')
        paidui.push('大王')
        return paidui
      }
      // 洗牌
      function shuffle() {
        let paidui = creatPoker()
        let i = paidui.length
        let res = []
        while (true) {
          let random = Math.floor(Math.random() * i)
          if (res.indexOf(paidui[random]) == -1) {
            res.push(paidui[random])
          }
          if (res.length === 54) {
            break
          }
        }
        return res
      }
      // 发牌
      function f2(puke) {
        let puke1 = puke.splice(0, 17)
        let puke2 = puke.splice(0, 17)
        let puke3 = puke.splice(0, 17)
        let dipai = puke.splice(0, 3)
        console.log('玩家1: ' + puke1)
        console.log('玩家2: ' + puke2)
        console.log('玩家3: ' + puke3)
        console.log('底牌： ' + dipai)
      }
      let pai = shuffle()
      f2(pai)
    </script>
  </body>
</html>
